home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 02 / c7 / mfchello.cpp < prev    next >
C/C++ Source or Header  |  1992-02-29  |  2KB  |  64 lines

  1. // mfchello.cpp RHS 1/5/92
  2.  
  3. #include<AFXWIN.H>
  4. #include"mfchello.h"
  5.  
  6. #define IDM_ABOUT   100
  7.  
  8. class HelloWindow : public CFrameWnd    // main window derived from CFrameWnd
  9.     {
  10. public:
  11.     HelloWindow();              // class constructor
  12.     afx_msg void OnPaint();     // declare message handling functions
  13.     afx_msg void OnAbout();
  14.     DECLARE_MESSAGE_MAP()       // declare message map
  15.     };
  16.  
  17. HelloWindow::HelloWindow()      // constructor for HelloWindow
  18.     {
  19.     LoadAccelTable("MainAccelTable");
  20.     Create(NULL, "MFCHello", WS_OVERLAPPEDWINDOW, rectDefault, 
  21.         NULL, "MainMenu");
  22.     }
  23.  
  24. void HelloWindow::OnPaint()     // WM_PAINT handling
  25.     {
  26.     CPaintDC dc(this);
  27.     dc.SetTextAlign(TA_BASELINE | TA_CENTER);
  28.     dc.SetBkMode(TRANSPARENT);
  29.  
  30.     CRect rect;
  31.     GetClientRect(rect);
  32.  
  33.     CString s = "Hello Windows, from MFC!";
  34.     dc.TextOut((rect.right/2), (rect.bottom/2), s, s.GetLength());
  35.     }
  36.  
  37. void HelloWindow::OnAbout()     // WM_COMMAND with wParam==IDM_ABOUT handling
  38.     {
  39.     CModalDialog about("AboutBox", this);
  40.     about.DoModal();
  41.     }
  42.  
  43. BEGIN_MESSAGE_MAP(HelloWindow, CFrameWnd) // message map definition
  44.     ON_WM_PAINT()
  45.     ON_COMMAND(IDM_ABOUT, OnAbout)
  46. END_MESSAGE_MAP()
  47.  
  48. class MFCHello : public CWinApp // main application class derived from CWinApp
  49.     {
  50. public:
  51.     BOOL InitInstance();        // declare InitInstance member function
  52.     };
  53.  
  54. BOOL MFCHello::InitInstance()   // define InitInstance member function
  55.     {
  56.     m_pMainWnd = new HelloWindow();
  57.     m_pMainWnd->ShowWindow(m_nCmdShow);
  58.     m_pMainWnd->UpdateWindow();
  59.     return TRUE;
  60.     }
  61.  
  62. MFCHello myApp;                 // instantiate the application class,
  63.                                 // and start the program
  64.